package com.jmeter.perf.controller;

import java.util.List;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jmeter.perf.entity.Administrativedivision;
import com.jmeter.perf.mapper.AdministrativedivisionMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@CacheConfig(cacheNames = "Administrativedivision")
public class AdministrativedivisionController {

	@Autowired
	private AdministrativedivisionMapper mapper;

	@GetMapping("/all")
	public List<Administrativedivision> selectList() {
		return mapper.selectList(null);
	}

	@GetMapping("/withcache")
	@Cacheable(key = "'pageNo,pageSize'")
	public IPage<Administrativedivision> page(@RequestParam(name = "pageNo", required = true) int pageNo, @RequestParam(name = "pageSize", required = true) int pageSize) {
		IPage<Administrativedivision> page = new Page<Administrativedivision>(pageNo, pageSize);
		return mapper.selectPage(page, null);

	}

	@GetMapping()
	public IPage<Administrativedivision> pageNoCache(@RequestParam(name = "pageNo", required = true) int pageNo, @RequestParam(name = "pageSize", required = true) int pageSize) {
		IPage<Administrativedivision> page = new Page<Administrativedivision>(pageNo, pageSize);
		return mapper.selectPage(page, null);

	}
}
